import { sendRequest } from '@/http';
import { setToken } from '@/utils/auth';

export interface LoginData {
  account: string;
  password: string;
}

export interface LoginRes {
  token: string;
}

export const login = (params: any) =>
  sendRequest({
    url: `/admin/staff/loginWithPassword`,
    method: 'post',
    data: params,
  }).then((res: LoginRes) => {
    // 保存token到localStorage
    if (res?.token) {
      setToken(res.token);
    }
    return res;
  });

// export const login = (params: any) => {
//   return Promise.resolve({
//     accessToken: '123',
//   });
// };

export const logout = () => {
  return new Promise((resolve) => {
    setTimeout(resolve, 500);
  });
};

export function getUserInfo() {
  // return sendRequest({
  //   url: `/admin/staff/querySelfInfo`,
  //   method: 'get',
  // });
  return {
    staffId: 1,
    branchId: 2,
    deptId: 3,
    deptName: 4,
    staffPhone: 5,
    createTime: 6,
    permissions: [],
    staffName: 7,
  };
}

// export function getUserPermission() {
//   return sendRequest({
//     url: `/admin/staff/permissions`,
//     method: 'get',
//   });
// }

export function getUserPermission() {
  return Promise.resolve([]);
}

export function getUserRoles() {
  return sendRequest({
    url: `/admin/staff/roles`,
    method: 'get',
  });
}

export function getMenuList() {
  return sendRequest({
    url: `/api/user/menu`,
    method: 'get',
  });
}

export function getTestData(data: any) {
  return Promise.resolve({ data });
}
